<?php
namespace app\log\model;
use app\common\model\Common;
use think\Db;
class RepairLog extends Common
{
	protected $table = "mps_repair_log";
	protected $autoWriteTimestamp = true;
	protected $createTime = 'addtime';
    protected $updateTime = false;
    protected $append = ['state_text'];


    /**
	 * 添加维修记录
	 * @param intger $repair_id 维修单id
	 * @param string $record    记录
	 */
	public function addLog($repair_id, $record)
	{
		$data = [
			'repair_id'		=> $repair_id,
			'goods_sn'		=> $record,
			'state'			=> 0,
			'addtime'		=> time(),
		];
		return Db::name('repairLog')->insert($data);
	}
	/**
	 * 添加维修取消备注
	 * @param intger $repair_id 维修单id
	 * @param string $record    取消备注
	 */
	public function addRemark($repair_id, $record)
	{
		$data = [
			'repair_id'		=> $repair_id,
			'goods_sn'		=> $record,
			'state'			=> 9,
			'addtime'		=> time(),
		];
		return Db::name('repairLog')->insert($data);
	}
	/**
	 * 添加维修取消备注
	 * @param intger $repair_id 维修单id
	 * @param string $record    取消备注
	 */
	public function addFailRemark($repair_id, $record)
	{
		$data = [
			'repair_id'		=> $repair_id,
			'goods_sn'		=> $record,
			'state'			=> 8,
			'addtime'		=> time(),
		];
		return Db::name('repairLog')->insert($data);
	}
	/**
	 * 获取器
	 */
    public function getStateTextAttr($value,$data)
    {
    	switch( $data['state'] ){
    		case 0: return '记录';break;
    		case 9: return '取消备注信息';break;
    		default: '异常';
    	}
    }
}